<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	 if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
   // $fields=array('id','name');
    $orderby='displayorder desc';
	$total='';
	$return['list']=pdo_getslice('jy_sns_board',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		$v['follow']=pdo_count('jy_sns_board_follow',array('bid'=>$v['id']));
		$v['posts']=pdo_count('jy_sns_post',array('bid'=>$v['id'],'deleted'=>0,'pid'=>0));
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'版块管理'),
			array('op'=>'edit','title'=>'添加版块'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'logo','title'=>'图标','type'=>'image'),
			array('name'=>'posts','title'=>'话题数','type'=>'string'),
			array('name'=>'follow','title'=>'关注数','type'=>'string'),
			array('name'=>'displayorder','title'=>'排序','type'=>'string'),
			array('name'=>'enabled','title'=>'状态','type'=>'radio','options'=>'enabled'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'标题','type'=>'string'),
		)
	);
	$return['enabled']=array('0'=>'禁用','1'=>'启用');
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_sns_board',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'版块管理'),
			array('op'=>'edit','title'=>'添加版块'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基础设置',
				'list'=>array(
					array('name'=>'title','title'=>'名称','type'=>'string'),
					array('name'=>'logo','title'=>'logo','type'=>'image'),
					array('name'=>'displayorder','title'=>'排序','type'=>'string'),
					array('name'=>'cid','title'=>'分类','type'=>'select','options'=>'cate','option_title'=>'name'),
					array('name'=>'desc','title'=>'描述','type'=>'text'),
					array('name'=>'banner','title'=>'版块Banner','type'=>'image'),
					array('name'=>'noimage','title'=>'允许发图','type'=>'switch'),
					array('name'=>'needcheck','title'=>'发帖需要审核','type'=>'switch'),
					array('name'=>'needcheckmanager','title'=>'版主发帖需要审核','type'=>'switch'),
					array('name'=>'needcheckreply','title'=>'回帖需要审核','type'=>'switch'),
					array('name'=>'needcheckreplymanager','title'=>'版主回帖需要审核','type'=>'switch'),
					array('name'=>'keyword','title'=>'关键词','type'=>'string'),					
					array('type'=>'choose','title'=>'选择版主','name'=>'cid','action'=>'get_member','choose_title'=>'选择版主'),
					array('name'=>'enabled','title'=>'状态','type'=>'switch'),
					array('name'=>'isrecommand','title'=>'是否推荐','type'=>'switch'),			
				)
			),
			array(
				'title'=>'积分',
				'list'=>array(
					array('type'=>'string','title'=>'话题积分','name'=>'postcredit','help'=>'删除话题，也扣除相应积分'),
					array('type'=>'string','title'=>'评论积分','name'=>'replycredit','help'=>'删除评论，也扣除相应积分'),
					array('type'=>'string','title'=>'设置版块精华积分','name'=>'bestboardcredit','help'=>'取消版块精华，也扣除相应积分'),
					array('type'=>'string','title'=>'设置全站精华积分','name'=>'bestcredit','help'=>'取消全站精华，也扣除相应积分'),
					array('type'=>'string','title'=>'设置版块置顶积分','name'=>'topboardcredit','help'=>'取消版块置顶，也扣除相应积分'),
					array('type'=>'string','title'=>'设置全站置顶积分','name'=>'topcredit','help'=>'取消全站精华，也扣除相应积分'),
					
					)
			),
		
			array(
				'title'=>'关注及分享',
				'list'=>array(
						array('type'=>'radio','title'=>'发帖强制关注','name'=>'needpostfollow','options'=>'is'),	
						array('type'=>'string','title'=>'分享标题','name'=>'share_title'),
						array('type'=>'image','title'=>'分享图片','name'=>'share_icon'),
						array('type'=>'text','title'=>'分享描述','name'=>'share_desc'),
					)
			),
			array(
				'title'=>'会员权限',
				'list'=>array(
					array('name'=>'showlevels','title'=>'商城会员等级浏览权限','type'=>'checkbox','options'=>'levels'),
					array('name'=>'postlevels','title'=>'商城会员等级发帖权限','type'=>'checkbox','options'=>'levels'),
					array('name'=>'postgroups','title'=>'商城会员组浏览权限','type'=>'checkbox','options'=>'groups'),
					array('name'=>'showgroups','title'=>'商城会员组发帖权限','type'=>'checkbox','options'=>'groups'),
					array('name'=>'showsnslevels','title'=>'社区会员等级浏览权限','type'=>'checkbox','options'=>'snslevel'),
					array('name'=>'postsnslevels','title'=>'社区会员等级发帖权限','type'=>'checkbox','options'=>'snslevel'),			
					)
			),
		/*	array(
				'title'=>'分销商权限',
				'list'=>array(
					array('type'=>'radio','title'=>'允许非分销商浏览','name'=>'notagent','options'=>'status'),
					array('type'=>'checkbox','title'=>'分销商等级浏览权限','name'=>'showagentlevels','options'=>'agentlevels','help'=>'不设置默认全部分销商等级'),
					array('type'=>'radio','title'=>'允许非分销商发帖','name'=>'notagentpost','options'=>'status'),
					array('type'=>'checkbox','title'=>'分销商等级发帖权限','name'=>'postagentlevels','options'=>'agentlevels','help'=>'不设置默认全部分销商等级'),			
					)
			),
			
			array(
				'title'=>'股东权限',
				'list'=>array(
					array('type'=>'radio','title'=>'允许非股东浏览','name'=>'notpartner','options'=>'status'),
					array('type'=>'checkbox','title'=>'股东等级浏览权限','name'=>'showpartnerlevels','options'=>'partnerlevels','help'=>'不设置默认全部股东等级'),
					array('type'=>'radio','title'=>'允许非股东发帖','name'=>'notpartnerpost','options'=>'status'),
					array('type'=>'checkbox','title'=>'股东等级发帖权限','name'=>'postpartnerlevels','options'=>'partnerlevels','help'=>'不设置默认全部股东等级'),						
					)
			),*/
		
		)
	);
	$return['cate']=pdo_getall('jy_sns_category',array('uniacid'=>$_SESSION['uniacid'],'enabled'=>1),array('id','name'));
	//print_r($cate);exit();
	$snslevel=pdo_getall('jy_sns_level',array('uniacid'=>$_SESSION['uniacid']),array('id','levelname'));
	foreach($snslevel as $v){
		$id=$v['id'];
		$sns[$id]=$v['levelname'];
	}
	$groups=pdo_getall('jy_weishop_member_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	foreach($groups as $v2){
		$id=$v2['id'];
		$group[$id]=$v2['title'];
	}
	$levels=pdo_getall('jy_weishop_member_level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	foreach($levels as $v3){
		$id=$v3['id'];
		$level[$id]=$v3['title'];
	}
	/*$agentlevels=pdo_getall('jy_commission_level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	foreach($agentlevels as $v4){
		$id=$v4['id'];
		$agentlevel[$id]=$v4['name'];
	}
	$partnerlevels=pdo_getall('jy_globonus_level',array('uniacid'=>$_SESSION['uniacid']),array('id','levelname'));
	foreach($partnerlevels as $v5){
		$id=$v5['id'];
		$partnerlevel[$id]=$v5['levelname'];
	}*/
	$return['snslevel']=$sns;
	$return['groups']=$group;
	$return['levels']=$level;
//	$return['agentlevels']=$agentlevel;
	//$return['partnerlevels']=$partnerlevel;
	$return['is']=array('0'=>'否','1'=>'是');
	$return['status']=array('0'=>'禁止','1'=>'允许');
	$return['enabled']=array('0'=>'禁用','1'=>'启用');
	$return['isrecommand']=array('0'=>'否','1'=>'是');
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写标题');
	}
	if(!$postdata['logo']){
		exi('请上传logo');
	}
	//$data=array_fields(array('isrecommand','name','image','displayorder','enabled'),$postdata);
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_sns_board',$postdata,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $postdata['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_sns_board',$postdata);
				exi('添加成功！','','list');
			}
			}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_sns_board',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_sns_board',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>